//
// Created by Christian Falch on 24/08/2021.
//

#pragma once

#include <chrono>
#include <string>

#include "RNSkLog.h"

namespace RNSkia {
class RNSkMeasureTime {
public:
    explicit RNSkMeasureTime(const std::string &name) : _name(name), _start(std::chrono::high_resolution_clock::now())
    {}

    ~RNSkMeasureTime()
    {
        auto stop = std::chrono::high_resolution_clock::now();
        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - _start).count();
        RNSkLogger::logToConsole("%s: %lld ms\n", _name.c_str(), duration);
    }

private:
    std::string _name;
    std::chrono::time_point<std::chrono::steady_clock> _start;
};
}; // namespace RNSkia
